<?php
/**
*
* @package sgp_ajax
* @version $Id: sgp_ajax.php 2008-07-03 22:47:00Z livewirestu $
* @copyright (c) 2008 www.phpbbireland.com
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

/**
* Haven't yet found a way to explicitly call a php function from JS, so for now, in any ajax call, we
* specify the function name as the first parameter. We then use a variable function to call the function
* and pass the appropriate parameters.
* Note that all data from the http request should be in a serialised format, as generated by the prototype
* serialize() function
*/

// Maintain a list of functions which are allowed to be called via this file to prevent users
// getting into functions they shouldn't
$allowed_funcs = array(
    'calendar:get_repeat_dates',
    'block_calendar:populate_table',    
);

$mode = request_var('mode', '');
unset($_GET['mode']);

if(isset($_GET['func']))
{
    $func = request_var('func', '');
}
else
{
    die('Something bad happened');
}

if(in_array($func, $allowed_funcs))
{
    list($func_location, $func_name) = explode(':', $func);
    $function_path = $phpbb_root_path . 'includes/sgp_ajax/ajax_' . $func_location . '.' . $phpEx;
    include_once($function_path);
    $returned_data = $func_name();
    
    // We have hopefully been returned to here with some data from the function we called
    if(sizeof($returned_data))
    {
        echo serialize($returned_data);   
    }
    else
    {
        die('No data received');
    }
}
else
{
    die('Not so fast, buddy!');
}
die;

?>
